:root {
    --primary: #007bff;
    --primary-hover: #0069d9;
    --background: #f8f9fa;
    --surface: white;
    --border: rgba(0,0,0,.125);
    --shadow: 0 2px 4px rgba(0,0,0,.1);
    --text: #333;
    --radius: 8px;
    --transition: all 0.2s ease-in-out;
}

@media (prefers-color-scheme: dark) {
    :root {
        --background: #1a1a1a;
        --surface: #2d2d2d;
        --text: #e6e6e6;
        --border: rgba(255,255,255,.125);
        --shadow: 0 2px 4px rgba(0,0,0,.3);
    }

    .ai-message {
        background: linear-gradient(135deg, #3d3d3d, #4d4d4d);
    }

    .product {
        border-color: rgba(255,255,255,.1);
    }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, 
        "Helvetica Neue", Arial, sans-serif;
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    background-color: var(--background);
    color: var(--text);
}

h1 {
    text-align: center;
    color: var(--primary);
    margin-bottom: 30px;
    background: linear-gradient(90deg, var(--primary), var(--primary-hover));
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.chat-container {
    height: 70vh;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    background-color: var(--surface);
    box-shadow: var(--shadow);
    backdrop-filter: blur(4px);
    overflow-y: auto !important;
}

.message {
    margin-bottom: 15px;
    padding: 16px 20px;
    border-radius: calc(var(--radius) * 1.5);
    max-width: 70%;
    position: relative;
    opacity: 0;
    animation: fadeIn 0.3s ease-in-out forwards;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-content {
    line-height: 1.5;
}

.message-time {
    font-size: 0.8em;
    opacity: 0.7;
    align-self: flex-end;
    margin-top: 4px;
}

.user-message .message-time {
    color: rgba(255,255,255,.7);
}

.ai-message .message-time {
    color: rgba(0,0,0,.7);
}

@media (prefers-color-scheme: dark) {
    .ai-message .message-time {
        color: rgba(255,255,255,.7);
    }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.user-message {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: var(--surface);
    margin-left: auto;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.ai-message {
    background: linear-gradient(135deg, #f0f0f0, #ffffff);
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}

.product {
    display: grid;
    gap: 16px;
    grid-template-columns: 100px 1fr;
    margin: 10px 0;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: var(--surface);
    transition: var(--transition);
}

.product:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,.1);
}

.product img {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: 4px;
    grid-row: span 2;
}

.product-info h3 {
    margin-top: 0;
    margin-bottom: 8px;
}

.input-container {
    display: flex;
    gap: 12px;
    box-shadow: var(--shadow);
    border-radius: var(--radius);
    padding: 16px;
    background-color: var(--surface);
    backdrop-filter: blur(4px);
}

.input-wrapper {
    flex: 1;
    position: relative;
}

.character-count {
    position: absolute;
    right: 8px;
    bottom: 8px;
    font-size: 0.8em;
    color: var(--text);
    opacity: 0.6;
    pointer-events: none;
}

#message-input {
    width: 100%;
    padding-right: 80px;
}

.mode-select,
#message-input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) / 2);
    font-family: inherit;
    font-size: 16px;
    outline: none;
    transition: var(--transition);
}

.mode-select:hover,
#message-input:hover {
    border-color: var(--primary);
}

.mode-select {
    appearance: none;
    background: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23007bff'%3e%3cpath d='M7 10l5 5 5-5z'/%3e%3c/svg%3e") no-repeat right 8px center/16px 16px;
    background-color: var(--surface);
    width: 120px;
    cursor: pointer;
}

#message-input {
    flex: 1;
}

button {
    background-color: var(--primary);
    color: var(--surface);
    border: none;
    border-radius: calc(var(--radius) / 2);
    padding: 8px 20px;
    cursor: pointer;
    transition: var(--transition);
}

button:hover {
    background-color: var(--primary-hover);
}

.loading-spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 8px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#send-button.loading {
    pointer-events: none;
}

#send-button.loading #button-text {
    display: none;
}

#send-button.loading #loading-spinner {
    display: inline-block;
}

/* Responsive design */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .chat-container {
        height: 60vh;
    }

    .message {
        max-width: 80%;
    }

    .product {
        grid-template-columns: 1fr;
    }

    .product img {
        width: 100%;
        height: auto;
        max-height: 200px;
        grid-row: 1;
        border-radius: 4px 4px 0 0;
    }

    .input-container {
        flex-direction: column;
    }

    .mode-select {
        width: 100%;
    }
}
